<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Wordpress主题开发学习笔记 - fangd123</title>
  <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="fangd123" /><meta name="description" content="本文是如下两个教程综合的笔记： Learn WordPress | LearnWebCode WordPress主题制作全过程（一）：主题文件构成 - 露兜博客 （一）文件结构 主页(按照优先顺序排列) 1.home.php" /><meta name="keywords" content="fangd123, 博客, 技术, 生活" />






<meta name="generator" content="Hugo 0.65.3 with theme even" />


<link rel="canonical" href="https://blog.fangd123.com/post/wordpress%E4%B8%BB%E9%A2%98%E5%BC%80%E5%8F%91%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" />
<link rel="apple-touch-icon" sizes="180x180" href="https://blog.fangd123.com/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="https://blog.fangd123.com/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="https://blog.fangd123.com/favicon-16x16.png">
<link rel="manifest" href="https://blog.fangd123.com/manifest.json">
<link rel="mask-icon" href="https://blog.fangd123.com/safari-pinned-tab.svg" color="#5bbad5">

<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<link href="https://blog.fangd123.com/dist/even.c2a46f00.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.css" integrity="sha256-7TyXnr2YU040zfSP+rEcz29ggW4j56/ujTPwjMzyqFY=" crossorigin="anonymous">


<meta property="og:title" content="Wordpress主题开发学习笔记" />
<meta property="og:description" content="本文是如下两个教程综合的笔记： Learn WordPress | LearnWebCode WordPress主题制作全过程（一）：主题文件构成 - 露兜博客 （一）文件结构 主页(按照优先顺序排列) 1.home.php" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://blog.fangd123.com/post/wordpress%E4%B8%BB%E9%A2%98%E5%BC%80%E5%8F%91%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" />
<meta property="article:published_time" content="2015-02-23T12:50:00+08:00" />
<meta property="article:modified_time" content="2015-02-23T12:50:00+08:00" />
<meta itemprop="name" content="Wordpress主题开发学习笔记">
<meta itemprop="description" content="本文是如下两个教程综合的笔记： Learn WordPress | LearnWebCode WordPress主题制作全过程（一）：主题文件构成 - 露兜博客 （一）文件结构 主页(按照优先顺序排列) 1.home.php">
<meta itemprop="datePublished" content="2015-02-23T12:50:00&#43;08:00" />
<meta itemprop="dateModified" content="2015-02-23T12:50:00&#43;08:00" />
<meta itemprop="wordCount" content="2141">



<meta itemprop="keywords" content="wordpress," /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Wordpress主题开发学习笔记"/>
<meta name="twitter:description" content="本文是如下两个教程综合的笔记： Learn WordPress | LearnWebCode WordPress主题制作全过程（一）：主题文件构成 - 露兜博客 （一）文件结构 主页(按照优先顺序排列) 1.home.php"/>

<!--[if lte IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
<![endif]-->

<!--[if lt IE 9]>
  <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->

</head>
<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="https://blog.fangd123.com/" class="logo">fangd123</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <a href="https://blog.fangd123.com/">
        <li class="mobile-menu-item">主页</li>
      </a><a href="https://blog.fangd123.com/categories/%E6%8A%80%E6%9C%AF">
        <li class="mobile-menu-item">技术</li>
      </a><a href="https://blog.fangd123.com/categories/%E7%94%9F%E6%B4%BB">
        <li class="mobile-menu-item">生活</li>
      </a><a href="https://blog.fangd123.com/post/">
        <li class="mobile-menu-item">归档</li>
      </a><a href="https://blog.fangd123.com/tags/">
        <li class="mobile-menu-item">标签</li>
      </a><a href="https://blog.fangd123.com/categories/">
        <li class="mobile-menu-item">分类</li>
      </a>
  </ul>
</nav>
  <div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="https://blog.fangd123.com/" class="logo">fangd123</a>
</div>

<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
        <a class="menu-item-link" href="https://blog.fangd123.com/">主页</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="https://blog.fangd123.com/categories/%E6%8A%80%E6%9C%AF">技术</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="https://blog.fangd123.com/categories/%E7%94%9F%E6%B4%BB">生活</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="https://blog.fangd123.com/post/">归档</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="https://blog.fangd123.com/tags/">标签</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="https://blog.fangd123.com/categories/">分类</a>
      </li>
  </ul>
</nav>
    </header>

    <main id="main" class="main">
      <div class="content-wrapper">
        <div id="content" class="content">
          <article class="post">
    
    <header class="post-header">
      <h1 class="post-title">Wordpress主题开发学习笔记</h1>

      <div class="post-meta">
        <span class="post-time"> 2015-02-23 </span>
        <div class="post-category">
            <a href="https://blog.fangd123.com/categories/%E6%8A%80%E6%9C%AF/"> 技术 </a>
            </div>
          <span class="more-meta"> 约 2141 字 </span>
          <span class="more-meta"> 预计阅读 5 分钟 </span>
        <span id="busuanzi_container_page_pv" class="more-meta"> <span id="busuanzi_value_page_pv"><img src="https://blog.fangd123.com/img/spinner.svg" alt="spinner.svg"/></span> 次阅读 </span>
      </div>
    </header>

    <div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content always-active">
    <nav id="TableOfContents">
  <ul>
    <li><a href="#主页按照优先顺序排列">主页(按照优先顺序排列)</a></li>
    <li><a href="#文章页">文章页：</a></li>
    <li><a href="#页面">页面</a></li>
    <li><a href="#分类">分类</a></li>
    <li><a href="#标签">标签</a>
      <ul>
        <li><a href="#作者">作者</a></li>
      </ul>
    </li>
    <li><a href="#日期页面">日期页面</a></li>
    <li><a href="#搜索结果">搜索结果</a></li>
    <li><a href="#404-未找到页面">404 (未找到)页面</a></li>
    <li><a href="#附件页面">附件页面</a></li>
  </ul>

  <ul>
    <li><a href="#单个页面的结构">单个页面的结构</a>
      <ul>
        <li><a href="#headerphp">header.php</a></li>
        <li><a href="#更改样式表stylecss的路径">更改样式表style.css的路径</a></li>
        <li><a href="#添加pingback">添加pingback</a></li>
        <li><a href="#更改博客名称和描述">更改博客名称和描述</a></li>
        <li><a href="#添加订阅feed链接">添加订阅feed链接</a></li>
        <li><a href="#刷新缓存">刷新缓存</a></li>
      </ul>
    </li>
    <li><a href="#footerphp">footer.php</a></li>
  </ul>

  <ul>
    <li><a href="#siderbarphp">siderbar.php</a></li>
    <li><a href="#indexphp">index.php</a>
      <ul>
        <li><a href="#文章骨架">文章骨架</a></li>
      </ul>
    </li>
    <li><a href="#singlephp">single.php</a></li>
  </ul>
</nav>
  </div>
</div>
    <div class="post-content">
      <p>本文是如下两个教程综合的笔记：
<a href="http://learnwebcode.com/learn-wordpress/">Learn WordPress | LearnWebCode</a>
<a href="http://www.ludou.org/create-wordpress-themes-template-hierarchy.html">WordPress主题制作全过程（一）：主题文件构成 - 露兜博客</a></p>
<hr>
<h1 id="一文件结构">（一）文件结构</h1>
<h2 id="主页按照优先顺序排列">主页(按照优先顺序排列)</h2>
<p>1.home.php
2.index.php</p>
<h2 id="文章页">文章页：</h2>
<p>single-{post_type}.php – 如果文章类型是videos（即视频），WordPress就会去查找single-videos.php（WordPress 3.0及以上版本支持）
single.php
index.php</p>
<h2 id="页面">页面</h2>
<p>自定义模板 – 在WordPress后台创建页面的地方，右侧边栏可以选择页面的自定义模板
page-{slug}.php – 如果页面的缩略名是news，WordPress将会查找 page-news.php（WordPress 2.9及以上版本支持）
page-{id}.php – 如果页面ID是6，WordPress将会查找page-6.php
page.php
index.php</p>
<h2 id="分类">分类</h2>
<p>category-{slug}.php – 如果分类的缩略名为news，WordPress将会查找category-news.php(WordPress 2.9及以上版本支持)
category-{id}.php -如果分类ID为6，WordPress将会查找category-6.php
category.php
archive.php
index.php</p>
<h2 id="标签">标签</h2>
<p>tag-{slug}.php – 如果标签缩略名为sometag，WordPress将会查找tag-sometag.php
tag-{id}.php – 如果标签ID为6，WordPress将会查找tag-6.php（WordPress 2.9及以上版本支持）
tag.php
archive.php
index.php</p>
<h3 id="作者">作者</h3>
<p>author-{nicename}.php – 如果作者的昵称为rami，WordPress将会查找author-rami.php（WordPress 3.0及以上版本支持）
author-{id}.php – 如果作者ID为6，WordPress将会查找author-6.php（WordPress 3.0及以上版本支持）
author.php
archive.php
index.php</p>
<h2 id="日期页面">日期页面</h2>
<p>date.php
archive.php
index.php</p>
<h2 id="搜索结果">搜索结果</h2>
<p>search.php
index.php</p>
<h2 id="404-未找到页面">404 (未找到)页面</h2>
<p>404.php
index.php</p>
<h2 id="附件页面">附件页面</h2>
<p>MIME_type.php – 可以是任何MIME类型 (image.php, video.php, audio.php, application.php 或者其他).
attachment.php
single.php
index.php</p>
<h1 id="二headerphp和footerphp">（二）header.php和footer.php</h1>
<p>本文是如下两个教程综合的笔记：
<a href="http://learnwebcode.com/learn-wordpress/">Learn WordPress | LearnWebCode</a>
<a href="http://www.ludou.org/create-wordpress-themes-template-hierarchy.html">WordPress主题制作全过程（四）：小试牛刀 - 露兜博客</a></p>
<hr>
<p>一个主题必须包含一下两个文件：</p>
<ul>
<li>index.php</li>
<li>style.css</li>
</ul>
<p>style.css除了确定主题的整个的CSS样式之外，同时也通过注释的形式确定主题的介绍信息，格式如下 :</p>
<pre><code>/*
Theme Name: 这里填主题名称
Theme URI: 这里填主题介绍的网址，没有就填你的博客网址吧
Description: 这里填主题的简短介绍
Version: 版本号
Author: 作者名
Author URI: 作者的网址
Tags: 标签，多个用半角逗号隔开
*/
</code></pre>
<h2 id="单个页面的结构">单个页面的结构</h2>
<p><img src="http://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2015/01/1422542721theme.png" alt="单个页面结构"></p>
<h3 id="headerphp">header.php</h3>
<p>如果把一个页面分为页头、内容、页脚三部分的话，该文件一般作为最终页面的页头部分，一般规定页面的<code>header</code>以及 <code>navi</code>部分内的内容。在其他文件中可以直接引用</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="p">&lt;</span><span class="nt">php</span> <span class="na">get_header</span><span class="err">();</span> <span class="err">?</span><span class="p">&gt;</span>
</code></pre></td></tr></table>
</div>
</div><h4 id="根据当前页面自动更改title">根据当前页面自动更改Title</h4>
<p>在<code>header.php</code>文件的<code>&lt;title&gt;</code>标签中插入PHP代码，判断当前页面类型，这里要使用到Wordpress内置的函数，示例代码如下</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="p">&lt;</span><span class="nt">title</span><span class="p">&gt;</span><span class="cp">&lt;?php</span> <span class="k">if</span> <span class="p">(</span> <span class="nx">is_home</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span>
        <span class="nx">bloginfo</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">);</span> <span class="k">echo</span> <span class="s2">&#34; - &#34;</span><span class="p">;</span> <span class="nx">bloginfo</span><span class="p">(</span><span class="s1">&#39;description&#39;</span><span class="p">);</span>
    <span class="p">}</span> <span class="k">elseif</span> <span class="p">(</span> <span class="nx">is_category</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span>
        <span class="nx">single_cat_title</span><span class="p">();</span> <span class="k">echo</span> <span class="s2">&#34; - &#34;</span><span class="p">;</span> <span class="nx">bloginfo</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">);</span>
    <span class="p">}</span> <span class="k">elseif</span> <span class="p">(</span><span class="nx">is_single</span><span class="p">()</span> <span class="o">||</span> <span class="nx">is_page</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span>
        <span class="nx">single_post_title</span><span class="p">();</span>
    <span class="p">}</span> <span class="k">elseif</span> <span class="p">(</span><span class="nx">is_search</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span>
        <span class="k">echo</span> <span class="s2">&#34;搜索结果&#34;</span><span class="p">;</span> <span class="k">echo</span> <span class="s2">&#34; - &#34;</span><span class="p">;</span> <span class="nx">bloginfo</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">);</span>
    <span class="p">}</span> <span class="k">elseif</span> <span class="p">(</span><span class="nx">is_404</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span>
        <span class="k">echo</span> <span class="s1">&#39;页面未找到!&#39;</span><span class="p">;</span>
    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
        <span class="nx">wp_title</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">,</span><span class="k">true</span><span class="p">);</span>
    <span class="p">}</span> <span class="cp">?&gt;</span><span class="p">&lt;/</span><span class="nt">title</span><span class="p">&gt;</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="更改样式表stylecss的路径">更改样式表style.css的路径</h3>
<p>Wordpress的主题<code>style.css</code>文件要想能够正确的被引用，采用传统的方式是不行的，因为Wordpress对于主题文件代码需要层层解析，所以我们需要采用Wordpress提供的函数进行引用。</p>
<p>两种方法：</p>
<ul>
<li>直接修改<code>header.php</code>文件中的<code>&lt;link&gt;</code>标签</li>
</ul>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="p">&lt;</span><span class="nt">link</span> <span class="na">rel</span><span class="o">=</span><span class="s">&#34;stylesheet&#34;</span> <span class="na">href</span><span class="o">=</span><span class="s">&#34;</span><span class="cp">&lt;?php</span> <span class="nx">bloginfo</span><span class="p">(</span><span class="s1">&#39;stylesheet_url&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="s">&#34;</span> <span class="na">type</span><span class="o">=</span><span class="s">&#34;text/css&#34;</span> <span class="na">media</span><span class="o">=</span><span class="s">&#34;screen&#34;</span> <span class="p">/&gt;</span>
</code></pre></td></tr></table>
</div>
</div><ul>
<li>在<code>function.php</code>添加</li>
</ul>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php">function themename_resources() {
  wp_enqueue_style(&#39;style&#39;,get_stylesheet_uri());
}

add_action(&#39;wp_enqueue_scripts&#39;,&#39;themename_resources&#39;);
</code></pre></td></tr></table>
</div>
</div><p>如果CSS文件不是<code>style.css</code>，我们可以用</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="cp">&lt;?php</span> <span class="nx">bloginfo</span><span class="p">(</span><span class="s1">&#39;template_url&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span>
</code></pre></td></tr></table>
</div>
</div><p>指定文件位置即可。</p>
<h3 id="添加pingback">添加pingback</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="p">&lt;</span><span class="nt">link</span> <span class="na">rel</span><span class="o">=</span><span class="s">&#34;pingback&#34;</span> <span class="na">href</span><span class="o">=</span><span class="s">&#34;</span><span class="cp">&lt;?php</span> <span class="nx">bloginfo</span><span class="p">(</span><span class="s1">&#39;pingback_url&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="s">&#34;</span> <span class="p">/&gt;</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="更改博客名称和描述">更改博客名称和描述</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nx">get_option</span><span class="p">(</span><span class="s1">&#39;home&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span> //输出你的博客首页网址
<span class="cp">&lt;?php</span> <span class="nx">bloginfo</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span>  //输出你的博客名称
<span class="cp">&lt;?php</span> <span class="nx">bloginfo</span><span class="p">(</span><span class="s1">&#39;description&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span>  //输出博客描述
</code></pre></td></tr></table>
</div>
</div><h3 id="添加订阅feed链接">添加订阅feed链接</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="p">&lt;</span><span class="nt">link</span> <span class="na">rel</span><span class="o">=</span><span class="s">&#34;alternate&#34;</span> <span class="na">type</span><span class="o">=</span><span class="s">&#34;application/rss+xml&#34;</span> <span class="na">title</span><span class="o">=</span><span class="s">&#34;RSS 2.0 - 所有文章&#34;</span> <span class="na">href</span><span class="o">=</span><span class="s">&#34;</span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nx">get_bloginfo</span><span class="p">(</span><span class="s1">&#39;rss2_url&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="s">&#34;</span> <span class="p">/&gt;</span>
<span class="p">&lt;</span><span class="nt">link</span> <span class="na">rel</span><span class="o">=</span><span class="s">&#34;alternate&#34;</span> <span class="na">type</span><span class="o">=</span><span class="s">&#34;application/rss+xml&#34;</span> <span class="na">title</span><span class="o">=</span><span class="s">&#34;RSS 2.0 - 所有评论&#34;</span> <span class="na">href</span><span class="o">=</span><span class="s">&#34;</span><span class="cp">&lt;?php</span> <span class="nx">bloginfo</span><span class="p">(</span><span class="s1">&#39;comments_rss2_url&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span><span class="s">&#34;</span> <span class="p">/&gt;</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="刷新缓存">刷新缓存</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="cp">&lt;?php</span> <span class="nx">flush</span><span class="p">();</span> <span class="cp">?&gt;</span>
</code></pre></td></tr></table>
</div>
</div><hr>
<h2 id="footerphp">footer.php</h2>
<p>引用方法</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="cp">&lt;?php</span> <span class="nx">get_footer</span><span class="p">();</span> <span class="cp">?&gt;</span>
</code></pre></td></tr></table>
</div>
</div><p>Wordpress函数</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="cp">&lt;?php</span> <span class="nx">wp_footer</span><span class="p">();</span> <span class="cp">?&gt;</span>
</code></pre></td></tr></table>
</div>
</div><h1 id="三indexphp和singlephp">（三）index.php和single.php</h1>
<p>本文是如下两个教程综合的笔记：
<a href="http://learnwebcode.com/learn-wordpress/">Learn WordPress | LearnWebCode</a>
<a href="http://www.ludou.org/create-wordpress-themes-template-hierarchy.html">WordPress主题制作全过程（七）：制作sidebar.php - 露兜博客</a></p>
<h2 id="siderbarphp">siderbar.php</h2>
<p>和<code>header.php</code>和<code>footer.php</code>一样，<code>sidebar.php</code>的引用代码如下</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="cp">&lt;?php</span> <span class="nx">get_sidebar</span><span class="p">();</span> <span class="cp">?&gt;</span>
</code></pre></td></tr></table>
</div>
</div><hr>
<h2 id="indexphp">index.php</h2>
<p><code>index.php</code>也就是俗称的首页，默认情况下显示的事文章列表（不过其实首页也可以设为其他的页面），关于文章列表的相关信息，有如下几个函数</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="p">&lt;</span><span class="nt">h3</span> <span class="na">class</span><span class="o">=</span><span class="s">&#34;title&#34;</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&#34;</span><span class="cp">&lt;?php</span> <span class="nx">the_permalink</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="s">&#34;</span> <span class="na">rel</span><span class="o">=</span><span class="s">&#34;bookmark&#34;</span><span class="p">&gt;</span><span class="cp">&lt;?php</span> <span class="nx">the_title</span><span class="p">();</span> <span class="cp">?&gt;</span><span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;&lt;/</span><span class="nt">h3</span><span class="p">&gt;</span> //标题和链接
<span class="cp">&lt;?php</span> <span class="nx">the_tags</span><span class="p">(</span><span class="s1">&#39;标签：&#39;</span><span class="p">,</span> <span class="s1">&#39;, &#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span> //标签
<span class="cp">&lt;?php</span> <span class="nx">the_time</span><span class="p">(</span><span class="s1">&#39;Y年n月j日&#39;</span><span class="p">)</span> <span class="cp">?&gt;</span> //日期
<span class="cp">&lt;?php</span> <span class="nx">comments_popup_link</span><span class="p">(</span><span class="s1">&#39;0 条评论&#39;</span><span class="p">,</span> <span class="s1">&#39;1 条评论&#39;</span><span class="p">,</span> <span class="s1">&#39;% 条评论&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;评论已关闭&#39;</span><span class="p">);</span> <span class="cp">?&gt;</span> //评论数

<span class="cp">&lt;?php</span> <span class="nx">the_excerpt</span><span class="p">();</span> <span class="cp">?&gt;</span> //输出摘要
<span class="cp">&lt;?php</span> <span class="nx">the_content</span><span class="p">();</span> <span class="cp">?&gt;</span>  //输出全文
</code></pre></td></tr></table>
</div>
</div><h3 id="文章骨架">文章骨架</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="cp">&lt;?php</span> <span class="k">if</span> <span class="p">(</span><span class="nx">have_posts</span><span class="p">())</span> <span class="o">:</span> <span class="k">while</span> <span class="p">(</span><span class="nx">have_posts</span><span class="p">())</span> <span class="o">:</span> <span class="nx">the_post</span><span class="p">();</span> <span class="cp">?&gt;</span>
    文章html骨架
<span class="cp">&lt;?php</span> <span class="k">endwhile</span><span class="p">;</span> <span class="cp">?&gt;</span>
<span class="cp">&lt;?php</span> <span class="k">else</span> <span class="o">:</span> <span class="cp">?&gt;</span>
    输出找不到文章提示
<span class="cp">&lt;?php</span> <span class="k">endif</span><span class="p">;</span> <span class="cp">?&gt;</span>
</code></pre></td></tr></table>
</div>
</div><hr>
<h2 id="singlephp">single.php</h2>
<p><code>single.php</code>文件主要是用来展示单个文章的页面，因此文章骨架这一套东西基本上一样。</p>
<h1 id="四commentphp">（四）comment.php</h1>
<p>本文是如下两个教程综合的笔记：
<a href="http://learnwebcode.com/learn-wordpress/">Learn WordPress | LearnWebCode</a>
<a href="http://www.ludou.org/create-wordpress-themes-template-hierarchy.html">WordPress主题制作全过程（十）：制作comments.php - 露兜博客</a></p>
<p>引用评论</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="cp">&lt;?php</span> <span class="nx">comments_template</span><span class="p">();</span> <span class="o">?</span>
</code></pre></td></tr></table>
</div>
</div><p>为了安全起见，防止恶意用户直接打开评论文件，在文件头部添加以下代码</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-php" data-lang="php"><span class="cp">&lt;?php</span>
    <span class="k">if</span> <span class="p">(</span><span class="nx">isset</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;SCRIPT_FILENAME&#39;</span><span class="p">])</span> <span class="o">&amp;&amp;</span> <span class="s1">&#39;comments.php&#39;</span> <span class="o">==</span>
        <span class="nx">basename</span><span class="p">(</span><span class="nv">$_SERVER</span><span class="p">[</span><span class="s1">&#39;SCRIPT_FILENAME&#39;</span><span class="p">]))</span>
        <span class="k">die</span> <span class="p">(</span><span class="s1">&#39;Please do not load this page directly. Thanks!&#39;</span><span class="p">);</span>
<span class="cp">?&gt;</span>
</code></pre></td></tr></table>
</div>
</div>
    </div>

    <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">fangd123</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">
        2015-02-23
        
    </span>
  </p>
  
  
</div>
<footer class="post-footer">
      <div class="post-tags">
          <a href="https://blog.fangd123.com/tags/wordpress/">wordpress</a>
          </div>
      <nav class="post-nav">
        <a class="prev" href="https://blog.fangd123.com/post/%E8%BF%87%E5%B9%B4%E5%B0%8F%E7%BB%93/">
            <i class="iconfont icon-left"></i>
            <span class="prev-text nav-default">过年小结</span>
            <span class="prev-text nav-mobile">上一篇</span>
          </a>
        <a class="next" href="https://blog.fangd123.com/post/%E4%B9%9D%E4%B8%89%E5%90%9B%E5%AD%90%E7%BB%88%E6%97%A5%E4%B9%BE%E4%B9%BE%E5%A4%95%E6%83%95%E8%8B%A5%E5%8E%89%E6%97%A0%E5%92%8E/">
            <span class="next-text nav-default">九三：君子终日乾乾，夕惕若，厉无咎</span>
            <span class="next-text nav-mobile">下一篇</span>
            <i class="iconfont icon-right"></i>
          </a>
      </nav>
    </footer>
  </article>
        </div>
        <div id="gitalk-container"></div>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js" crossorigin="anonymous"></script>
    <script type="text/javascript">
      var gitalk = new Gitalk({
        id: '2015-02-23 12:50:00 \x2b0800 CST',
        title: 'Wordpress主题开发学习笔记',
        clientID: 'e7701fe6c1c3f1819cca',
        clientSecret: '0279597bf6b736da28a66ac649db4851303b9d95',
        repo: 'fangd123.github.io',
        owner: 'fangd123',
        admin: ['fangd123'],
        body: decodeURI(location.href)
      });
      gitalk.render('gitalk-container');
    </script>
    <noscript>Please enable JavaScript to view the <a href="https://github.com/gitalk/gitalk">comments powered by gitalk.</a></noscript>

  

  

      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="social-links">
      <a href="mailto:fangd123@gmail.com" class="iconfont icon-email" title="email"></a>
      <a href="https://github.com/fangd123" class="iconfont icon-github" title="github"></a>
      <a href="https://weibo.com/p/1005051761690660/" class="iconfont icon-weibo" title="weibo"></a>
      <a href="https://www.zhihu.com/people/fang-wen-da" class="iconfont icon-zhihu" title="zhihu"></a>
      <a href="http://localhost:1313" class="iconfont icon-gitlab" title="gitlab"></a>
      <a href="http://localhost:1313" class="iconfont icon-bilibili" title="bilibili"></a>
  <a href="https://blog.fangd123.com/index.xml" type="application/rss+xml" class="iconfont icon-rss" title="rss"></a>
</div>

<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://gohugo.io">Hugo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 - 
    <a class="theme-link" href="https://github.com/olOwOlo/hugo-theme-even">Even</a>
  </span>

  <div class="busuanzi-footer">
    <span id="busuanzi_container_site_pv"> 本站总访问量 <span id="busuanzi_value_site_pv"><img src="https://blog.fangd123.com/img/spinner.svg" alt="spinner.svg"/></span> 次 </span>
      <span class="division">|</span>
    <span id="busuanzi_container_site_uv"> 本站总访客数 <span id="busuanzi_value_site_uv"><img src="https://blog.fangd123.com/img/spinner.svg" alt="spinner.svg"/></span> 人 </span>
  </div>

  <span class="copyright-year">
    &copy; 
    2014 - 
    2020
    <span class="heart">
      <i class="iconfont icon-heart"></i>
    </span>
    <span class="author">fangd123</span>
  </span>
</div>
    </footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont icon-up"></i>
    </div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/slideout@1.0.1/dist/slideout.min.js" integrity="sha256-t+zJ/g8/KXIJMjSVQdnibt4dlaDxc9zXr/9oNPeWqdg=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.js" integrity="sha256-XVLffZaxoWfGUEbdzuLi7pwaUJv1cecsQJQqGLe7axY=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://blog.fangd123.com/dist/even.26188efa.min.js"></script>








</body>
</html>
